//前端controller层
app.controller('brandController', function ($scope,$controller,brandService) {

    //继承baseController(注意引用时需要导入继承的父类js文件)  注意需要在controller层中引用$controller标签
    $controller('baseController',{$scope:$scope});


    //查询所有商品分类
    $scope.findAll = function () {
        brandService.findAll().success(
            function (response) {
                $scope.list = response;
            }
        );
    }

    //查询所有商品分类(分页)
    $scope.findPage = function (page, size) {
        brandService.findPage(page,size).success(
            function (response) {
                $scope.paginationConf.totalItems = response.total;
                $scope.list = response.rows;
            }
        );
    }

    //新增商品类别
    $scope.save = function () {
        var object = null;
        if ($scope.entity.id != null) {
            object = brandService.update($scope.entity);
        }else{
            object = brandService.add($scope.entity);
        }
        object.success(
            function (response) {
                if (response.success) {
                    $scope.reloadList();  //重新加载
                } else {
                    alert(response.message);
                }
            }
        );
    }

    //查寻商品类别
    $scope.findOne = function (id) {
        brandService.findOne(id).success(
            function (response) {
                $scope.entity = response;
            }
        );
    }






    //删除商品类别
    $scope.delet = function () {
        if (confirm("确认删除？")) {
            brandService.delet($scope.selectIds).success(
                function (response) {
                    if (response.success) {
                        $scope.reloadList();  //重新加载
                    } else {
                        alert(response.message);
                    }
                }
            );
        }
    }



    //全局条件查询
    $scope.search = function (page, size) {
        brandService.search($scope.searchEntity,page,size).success(
            function (response) {
                $scope.paginationConf.totalItems = response.total;
                $scope.list = response.rows;
            }
        );
    }
});